<?php
namespace app\home\extend;
require_once ROOT_PATH . 'vendor/aliyun/api_sdk/vendor/autoload.php';
use Aliyun\Core\Config;
use Aliyun\Core\Profile\DefaultProfile;
use Aliyun\Core\DefaultAcsClient;
use Aliyun\Api\Sms\Request\V20170525\SendSmsRequest;
use Aliyun\Api\Sms\Request\V20170525\SendBatchSmsRequest;
use Aliyun\Api\Sms\Request\V20170525\QuerySendDetailsRequest;

// 加载区域结点配置
Config::load();
class sms
{

    static $acsClient = null;

    /**
     * 取得AcsClient
     */
    public static function getAcsClient() {
        $product = "Dysmsapi";
        $domain = "dysmsapi.aliyuncs.com";
        $accessKeyId = "LTAIta8ZB9BHxFI7";

        $accessKeySecret = "6C4iJ7kCPj8uFY1HZ9u17ibfRyB0bu";
        $region = "cn-hangzhou";
        $endPointName = "cn-hangzhou";
        if(static::$acsClient == null) {
            $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
            DefaultProfile::addEndpoint($endPointName, $region, $product, $domain);
            static::$acsClient = new DefaultAcsClient($profile);
        }
        return static::$acsClient;
    }

    /**
     * 发送短信
     */
    public static function sendSms($mobile , $code , $temp) {
        $request = new SendSmsRequest();
        $request->setPhoneNumbers($mobile);
        $request->setSignName("阿里云短信测试专用");
        $request->setTemplateCode( $temp );
        $request->setTemplateParam(json_encode(array(
            "code"=> $code
        ), JSON_UNESCAPED_UNICODE));
        $acsResponse = static::getAcsClient()->getAcsResponse($request);
        return $acsResponse;
    }
}